home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 2 / Apprentice-Release2.iso / Tools / Languages / Mops 2.5 / Quick Edit ƒ / Subject Glossary / OOP < prev    next >
Encoding:
Text File  |  1992-11-27  |  13.0 KB  |  292 lines  |  [TEXT/MSET]

  1. CLASS DEFINITION
  2.  
  3. :CLASS    --  : name  super{ cname1 cname2 } opt
  4.     Begins definition of a new class.  One or more classnames can be 
  5.     designated as superclass(es).  There are optional parameters that may 
  6.     also be declared after the superclass list, including n INDEXED, LARGE, 
  7.     and GENERAL.  
  8. ;CLASS    --    Ends definition of a class.
  9.  
  10. SUPER{    --  : cname1 cname2 } opt
  11.     Used to declare the superclass(es) when defining a class. See :class.
  12.     
  13. GENERAL    --
  14.     Optional class declaration that will allow late binding when this class 
  15.     is used as an ivar.  But note that GENERAL classes may not be used to 
  16.     map ivars to Mac toolbox calls because the class header information will 
  17.     be included.  INDEXED classes are automatically GENERAL.  
  18. LARGE    --
  19.     Sets the "large" option on an indexed class, allowing the number of 
  20.     elements to be greater than 32K.  
  21. INDEXED    n --
  22.     Sets a class and its subclasses to indexed, of element byte width n.  
  23.     Used after the superclass declaration list when defining a new class.  
  24.     Note that when instantiating an indexed class, you MUST precede the 
  25.     instance name with the number of elements you wish that instance to 
  26.     have.  Also note that all indexed classes are automatically declared to 
  27.     be GENERAL, so you may not used indexed classes to map into toolbox 
  28.     calls.  Also, n must be < 32K (see LARGE).  
  29.  
  30. :M    --  : name:
  31.     Begins definition of a method within a class.  Note that name: MUST end 
  32.     with a colon (:).  
  33. ;M    --    Ends definition of a method in a class.
  34.  
  35. PRIVATE    --
  36.     Use within a class definition.  Makes the following methods private—that 
  37.     is, they will be accessible from within this class or any of its 
  38.     subclasses, but not from anywhere else.  The criterion is simply that a 
  39.     call to Self of Super may access a private method, but nothing else can.  
  40.     Note that for this reason you can't late-bind to a private method, even 
  41.     if you do it from within the class itself.  
  42. PUBLIC    --
  43.     Makes the following methods public—that is, they will be accessible from 
  44.     anywhere.  PRIVATE and PUBLIC may be used any number of times within the 
  45.     one class definition.  Methods are initially public when a class 
  46.     compilation starts.  
  47.  
  48. CallFirst    --  : methodname:
  49.     The next method definition will always execute the method indicated by 
  50.     methodname: BEFORE it is executed by a subclass.  Provides a way for 
  51.     superclasses to limit the extent to which subclasses may override a 
  52.     method.  
  53. CallLast    --  : methodname:
  54.     The next method definition will always execute the method indicated by 
  55.     methodname: AFTER it is executed by a subclass.  Provides a way for 
  56.     superclasses to limit the extent to which subclasses may override a 
  57.     method. 
  58.     
  59. SELF    -- obj
  60.     Object reference to self.  Only used in a class definition.  SELF is not 
  61.     necessarily the same as ^BASE, because of multiple inheritance.  
  62. SUPER    -- obj
  63.     Use within a class method definition to refer to self, an instance of 
  64.     the class, but the superclass method will be invoked.  
  65.  
  66.  
  67. LATE BINDING
  68. [    --
  69.     Begins an expression with a late bound message that computes the address 
  70.     of the object to recieve the message.  e.g.  get: [ 0 at: anArray ] .  
  71.     This is an alternative syntax to that provided by **, [], and [self].  
  72. ]    --  See above.
  73.  
  74. note that [SELF], [], and ** are all synonyms.
  75. [SELF]    obj selid --
  76.     Late binds whatever is on the stack to the given method.  e.g.  obj 
  77.     get: [self] .  You must be sure that obj really does point to an 
  78.     object. 
  79. []    ^obj selid --    See above.
  80. **    ^obj selid --    See above.
  81.  
  82.  
  83. STANDARD METHODS
  84.  
  85. CLASSINIT:    --
  86.     Our standard constructor method.  The default message that is ALWAYS 
  87.     sent to an object at time of instantiation, even ivars.  Note that if 
  88.     parameters are to be included for a classinit: for an INDEXED class, the 
  89.     #elements must precede those parameters (#elems must be top item on 
  90.     stack) at instantiation time (read that again).  Note that for class 
  91.     object classinit: is a null method, that is it does nothing.  
  92.  
  93. ADDR:    -- ^base    
  94.     Returns the address of the beginning of an object's ivars.
  95. CLASS:    -- class    Returns the class pointer for an object.
  96. COPYTO:    obj --
  97.     Copies the ivar part of the passed in object to self.  Doesn't check 
  98.     type - be careful.  
  99. DUMP:    --    Performs a formatted dump of a class.
  100. LENGTH:    -- len
  101.     Gets total length of object.  Length will include class header 
  102.     information only if class is of type GENERAL.  Otherwise, length is 
  103.     merely the length of the ivar data field(s).  
  104. PRINT:    --        Use to display a class, default is just a DUMP:.
  105. RELEASE:    --
  106.     Our standard destructor method.  Any objects that allocate heap storage 
  107.     will redefine this appropriately.  Our convention is that an object will 
  108.     release ALL its storage when it gets a release: message.  Other methods 
  109.     can be provided to partly release storage, as needed.  
  110.  
  111.  
  112.  
  113. CONSOLE INSPECTION
  114.  
  115. .CLASS:    --    A method.  Prints the name of the class of the given object.
  116. .ID:    --    A method.  Prints the name of the given object, if it has a name.
  117.  
  118.  
  119. MISCELLANEOUS
  120.  
  121. BYTES    n --  : ivarname
  122.     Bytes is used as the ivar allocation primitive for basic classes.  
  123.     Allocates n bytes as a named instance variable of an object.  You can 
  124.     use bytes to map a Toolbox data structure as an object when named access 
  125.     to some of the fields is not needed (but you must know the proper 
  126.     length).  
  127.  
  128. BIND_WITH    obj --<selector> obj-modified  cfa
  129.     If you are late-binding in a loop, it can be much faster if you do the 
  130.     bind just once, then reuse the resulting cfa each time in the loop.  
  131.     This way you only have to perform the method search once.  To bind 
  132.     initially and get the cfa, use BIND_WITH.  Usage: (saveCfa and ^obj-mod 
  133.     are values or locals).  (get object's address) bind_with someSelector: 
  134.     -> saveCfa -> ^obj-mod.  (in the loop) ^obj-mod saveCfa ex-method.  
  135. SET_CLASS    obj theClass --
  136.     SET_CLASS is a utility word used to patch nucleus objects when their 
  137.     classes are defined in higher-level files.  Actually it could be used to 
  138.     change the class of any object, if anyone is silly enough to want to do 
  139.     that.  
  140. SET_TO_CLASS    objPtr --  : cname
  141.     If you need to declare the object pointer before the class exists, use 
  142.     SET_TO_CLASS once the class is defined, thus: ' someOP set_to_class 
  143.     someClass.  
  144.  
  145.  
  146. STANDARD CLASSES
  147.  
  148. (COL)    --  : name
  149.     Collections are ordered lists with a current size.  We implement them by 
  150.     multiply inheriting the generic (COL) class with the array class of the 
  151.     appropriate width.  We use a few tricks to avoid late binding to self in 
  152.     loops.  
  153. ARRAY    #elems --  : name
  154.     The basic 4-byte cell one-dimension array.  Class is INDEXED.
  155. BOOL    --  : name
  156.     Subclass of byte.  Note that since the datalength of aMops class bool is 
  157.     1, this class should not be used to map into a Toolbox record of type 
  158.     BOOLEAN because the Pascal type boolean has a length of 2 (Use the Mops 
  159.     class INT for a Toolbox boolean).  
  160. BYTE    --  : name    A standard 1-byte variable class.
  161. DICADDR    --  : name
  162.     DICADDR is a relocatable dictionary address class - use to store 
  163.     non-executable dictionary addresses.  
  164. HANDLE    --  : name    The standard class for handles.
  165. HANDLEARRAY    #elems --  : name
  166.     HANDLEARRAY and HANDLELIST are for the implementation of collections of 
  167.     heap-based objects.  HandleArray has normal array properties.  Use 
  168.     HandleList if the number of elements may grow arbitrarily large, and if 
  169.     indexing isn't so important.  HandleArray also includes methods to allow 
  170.     the array to be used as a stack - needed for FileList.  
  171. HANDLELIST    #elems --  : name
  172. HANDLELIST allows the implementation of a list of heap-based objects.  
  173.     Unlike HANDLEARRAY, the list can be of indefinite length.  We use a heap 
  174.     block to store the handles to the objects contiguously, rather than have 
  175.     a separate block for each handle and link them together.  This saves on 
  176.     memory overhead and reduces the number of memory manager calls.  It also 
  177.     reflects the assumption that insertions and deletions into the middle of 
  178.     the list will be infrequent, as these could be more inefficient than 
  179.     with a linked scheme.  We expect that elements will normally be added to 
  180.     the end, and probably not removed at all, or not very often.  
  181. INDEXED-OBJ    --  : name
  182.     Class INDEXED-OBJ is the generic superclass for all arrays.  Here we 
  183.     define the general indexed methods, which apply regardless of indexed 
  184.     width.  
  185. LONGWORD    --  : name    Generic superclass for var, handle etc.
  186. OBJHANDLE    --  : name
  187.     An OBJHANDLE is a handle that points to an object in the heap.
  188. OBJPTR    --  :  name
  189.     An object pointer is a "low-level" entity, rather like a value.  The 
  190.     syntax for object pointers is: objPtr anObjptr class_is theClass 
  191. OBJ_ARRAY    #elems --  : name
  192.     OBJ_ARRAY is a generic superclass which makes it easy to generate an 
  193.     array of objects of a given class.  Just define a new class which 
  194.     multiply inherits from the given class (or classes) and OBJ_ARRAY (which 
  195.     must come last).  This will add an indexed section to each object of the 
  196.     new class, with elements wide enough to contain objects of the original 
  197.     class.  Then SELECT: "switches in" the selected element to be the 
  198.     "current" element, and all the normal methods of the class can then be 
  199.     used.  Note the use of"32767 indexed" in the class definition.  
  200. ORDERED-COL    #elems --  : name
  201.     Ordered-Collection is a collection of 4-byte cells.  A subclass of (col) 
  202.     and array.  
  203. PTR    --   : name    A standard class.  For toolbox pointers.
  204. RESOURCE    --   : name
  205.     Provides basic support for Toolbox resources.
  206. SEQUENCE    #elems -- j  : name
  207.     A generic superclass for classes which have multiple items which 
  208.     frequently need to be looked at in sequence.  At present the main 
  209.     function of Sequence is to implement the EACH: method, which makes it 
  210.     very simple to deal with each element.  Sequence can be multiply 
  211.     inherited with any class which implements the FIRST?: and NEXT?: 
  212.     methods.  The actual implementation details are quite irrelevant, as 
  213.     long as these methods are supported.  
  214. VAR    --   : name
  215.     The standard variable class.  Subclass of longword that adds the +: and 
  216.     -: methods.  Useful as an ivar that maps into a Toolbox LONGINT record 
  217.     structure.  
  218. X-ADDR    --   : name
  219.     X-ADDR is an executable dictionary address class.  The only significant 
  220.     difference to DicAddr is that there is an Exec: method and no Get: 
  221.     method.  But if we ever have to separate code and data, having a 
  222.     separate class could prove very useful.  
  223. X-ARRAY    #elems --   : name
  224.     A subclass of ARRAY, can execute its elements (which are cfas of Mops 
  225.     words).  
  226. X-COL    #elems --   : name
  227.     X-COL is a collection of executable word addresses.  A subclass of (col) 
  228.     and x-array.  
  229.  
  230.  
  231. PRIMITIVES
  232.  
  233. ^BASE    -- addr
  234.     Addr is the base address of the private data of the object.  Only used 
  235.     in a class definition.  Same as addr: self.  
  236. OBJ    -- obj
  237.     Called from within an inline method.  Passes the object's base and 
  238.     displacement to Handlers to generate the correct address.  Optimization 
  239.     will then apply.  
  240. OBJECT    -- class
  241.     The root class of all classes.  Only used as a declared superclass when 
  242.     defining a new class.  Note that class object has the pre-defined 
  243.     methods class:, .id:, .class:, addr:, length:, copyto:, classinit:, 
  244.     release:, dump:, and print:.  So ALL objects possess these methods.  
  245.     Some of these methods do nothing, for class object.  
  246. OBJLEN    -- n    Computes total data length of current object.
  247. CHKSAME    obj -- obj
  248.     A check that two objects are of exactly the same class.  Aborts with 
  249.     error message if not.  
  250. CHKCLASS    cfa -- cfa
  251. Aborts and issues error message if the cfa does not refer to a class.  
  252. ?>CLASS    obj -- class
  253.     Converts the pointer to an object to a pointer to its class.  Aborts if 
  254.     failure.  
  255. ?CLASS    --    Error if not compiling a class definition.
  256. CL1    --    Cleans up the class compiler data on an abort.
  257. CL>LEN    #els class -- #els len
  258.     Gets data length of object given #els and class.
  259. DFA    class -- dfa
  260.     Given a pointer to a class, returns the data field address.  First 2 
  261.     bytes are the data length, second 2 bytes are the width of the indexed 
  262.     elements.  
  263. DLEN&XWID    class -- dlen xwid
  264.     Given a class pointer, retuns the ivar datalength and width of the 
  265.     indexed elements.  
  266. EXMID    obj selID --
  267.     Executes a method given its sel ID.  Used in late binding.
  268. FFA    ^class -- ffa
  269.     Given a pointer to a class, returns the flag field address.
  270. FINDM    selID class -- offs cfa    Finds a method in a class.
  271. GETDLEN    obj -- n    Gets length of object's named ivars.
  272. IFA    class -- ifa
  273.     Given a pointer to a class, returns the ivar field address.
  274. IVFINDM    selID ^ivar -- offs cfa    Looks for a method in
  275. IX    -- ifa
  276.     Called from within an inline method.  Compiles code to generate the 
  277.     indexed address.  
  278. META    -- class
  279.     META is the super class of Object - top of all inheritance.
  280. MFA    class -- mfa    Given a pointer to a class, returns the methods field address.
  281. RELCNT    -- n
  282.     A value.  For testing - counts release: msgs to make sure we're 
  283.     releasing everything.  
  284. SFA    class -- sfa
  285.     Given a pointer to a class, returns the superclass field address, which 
  286.     is an N-way pointer.  
  287. SUPER(    --  : cname1 cname2 } opt    Synonym for super{.
  288. XWID    class -- xwid    Given a class pointer, retuns the width of the indexed elements.
  289. ^CLASS    -- class    Addr of the class we're currently compiling.
  290. ^DLEN    obj -- dfa    Returns the dfa for the given object.
  291. ^ELEM    idx -- addr    Leaves addr of indexed element.
  292.